package cn.zye.msa;

import java.util.ArrayList;
import java.util.List;

import cn.creable.gridgis.controls.MapControl;
import cn.creable.gridgis.geodatabase.FeatureInfo;
import cn.creable.gridgis.geometry.Arithmetic;
import cn.creable.gridgis.geometry.IEnvelope;
import cn.creable.gridgis.geometry.IPoint;
import cn.creable.gridgis.geometry.Point;
import cn.creable.gridgis.mapLayer.ILayer;
import cn.creable.gridgis.shapefile.ShapefileLayer;

public class SearchTool4Map {
	private MapControl mapControl;
	public SearchTool4Map(MapControl mp){
		this.mapControl = mp;
	}
	
	public void locationSearch(String str){
		int count = mapControl.getMap().getLayerCount();
		for (int i = 0; i < count; ++i) {
			ILayer layer = mapControl.getMap().getLayer(i);
			if (layer instanceof ShapefileLayer) {
				FeatureInfo[] f = null;
				try {
					f = mapControl.searchFeature(layer.getName(),
							null, "GEONAME = '"+str+"'", null, null, null);
					if (f != null) {
						for (int j = 0; j < f.length; j++) {
							FeatureInfo fi = f[j];
							IEnvelope extend = mapControl.getExtent();
							IPoint pt = new Point((f[j].xmin+f[j].xmax)/2,(f[j].ymin+f[j].ymax)/2);
							extend.centerAt(pt);
							pt = null;
							mapControl.refresh(extend);
							mapControl.flashFeature(f[j].layerID,f[j].objectID);
						}
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
